<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<style>
    .message {
        color: red;
    }
</style>
<script type="text/javascript">
    $(function () {
        initSelect(false, "#departList", ${departList}, false);
        initSelect(false, "#roleList", ${roleList}, false);

        //学号输入验证
        $.CurrentDialog.find("#no").on('input propertychange', function () {
            var no = $(this).val();
            if (no.length == 8) {
                noCheck(no);
            }
        });
        $(".control-label x180").each(function () {
            $(this).bind('input propertychange', function () {
                $(".msg").hidden();
            })
        })

    });

    var flag1 = false;
    //登录名Ajax验证
    function noCheck(no) {
        Dracula.post("user/noCheck.shtml?no="+no, null, checkBack);
    }

    function checkBack(json){
        if (json.code == 0) {
            $.CurrentDialog.find("#noMsg").html("学号可用");
            $.CurrentDialog.find("#noMsg").css("color", "green");
            flag1 = true;
        } else {
            $.CurrentDialog.find("#noMsg").html(json.msg);
            $.CurrentDialog.find("#noMsg").css("color", "red");
            flag1 = false;
        }
    }

    function check() {
        if (!flag1) {
            $(this).alertmsg('warn', '学号为空或已存在，请更换后再试！', {
                displayMode: 'slide',
                displayPosition: 'topcenter',
                okName: '好的',
                title: '注意'
            });
            return false;

        } else {
            //密码加密
            var pwd = $.CurrentDialog.find("#no").val();
            var passd = hex_md5(pwd);
            $.CurrentDialog.find("#password").val(passd);
            return true;
        }
    }
    ;
</script>

<form action="user/addSubmit.shtml" class="pageForm" id="addForm"
      data-toggle="validate" data-callback="doAjaxCallBackForDialog"
      method="post" data-toggle="ajaxform"
      data-validator-option="{stopOnError:false, timely:2}">
    <div class="bjui-pageContent">
        <div class="panel panel-default">
            <div class="panel-heading" align="center">新增社员</div>
            <input type="hidden" name="password" id="password">
            <div class="panel-body">
                <table class="table table-condensed table-hover">
                    <tbody>
                    <tr>
                        <td width="100px"><label class="control-label x180">学号：</label></td>
                        <td width="150px">
                            <input type="text" name="no" id="no" class="textChange" data-rule="required;length[~8]">
                            <span class="message" id="noMsg">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="100px"><label class="control-label x180">姓名：</label></td>
                        <td width="150px">
                            <input type="text" name="name" class="textChange" data-rule="required;username;length[~10]"
                                   data-rule-username="[/^[\u0391-\uFFE5]{1,}$/,'用户名必须是中文']">
                            <span class="message">*</span>
                        </td>
                    </tr>
                    <tr>
                        <td width="100px"><label class="control-label x180">部门：</label></td>
                        <td width="150px"><select name="departId" id="departList"
                                                              data-width="210" class="form-control"
                                                              data-toggle="selectpicker"
                                                              data-size="10" data-live-search="true"
                                                              data-rule="required;">
                        </select><span class="message">*</span></td>
                    </tr>
                    <tr>
                        <td width="100px"><label class="control-label x180">角色：</label></td>
                        <td width="150px"><select name="roleId" id="roleList"
                                                  data-width="210" class="form-control"
                                                  data-toggle="selectpicker"
                                                  data-size="10" data-live-search="true"
                                                  data-rule="required;">
                        </select><span class="message">*</span></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="bjui-pageFooter">
        <ul>
            <li>
                <button type="submit" class="btn-primary" id="submit" onClick="return check()">提交</button>
            </li>
            <li>
                <button type="button" class="btn-close">关闭</button>
            </li>
        </ul>
    </div>
</form>
